﻿package divinity.utils
{
	
	public class Calculator
	{		
	
		public function Calculator(lock:Class=null)
		{			
			
				
			
		}		
		/*
		*
		*
		*
		*/
		public function getAngle(vx:Number,vy:Number):Number
		{
			var a:Number=Math.atan2(vy,vx);
			var k:Number=(360 * a )/ (2 * Math.PI);
			return k;
			
		}
		
		public function getAngleTemp(vx:Number,vy:Number):Number
		{
			var a:Number=(Math.atan(Math.abs(vy)/Math.abs(vx)))*2;
			//a=a.toFixed(2);
			var k:Number=180/(Math.PI*a);					
			return a;
			
		}
		public function getAngleRad(vx:Number,vy:Number):Number
		{
			var k:Number=Math.atan2(vy,vx);
			return k;
			
		}
		public function getVector(ang:Number):Object
		{
			var props:Object={};
			
			
			props.vx=Math.cos(ang*(Math.PI/180))
			props.vy=Math.sin(ang*(Math.PI/180));
			//props.vx=props.vx.toFixed(2);
			//props.vy=props.vy.toFixed(2);
			return props;
			
			
		}
		public function point2point(m1:Object,m2:Object):Object
		{
			
			var props:Object={};
			var dx:Number=m2.x - m1.x;
			var dy:Number=m2.y - m1.y;
			var d:Number=Math.abs(Math.sqrt(dx * dx + dy * dy));
			var vx:Number=dx / d;
			var vy:Number=dy / d;
			
				
			
			props.vx=vx.toFixed(2);
			props.vy=vy.toFixed(2);;
			props.k=getAngle(vx,vy);;
			props.kr=getAngleRad(vx,vy);
			props.d=d;
			props.tmp=getAngleTemp(vx,vy)
			
			return props;
			
			
			
			
		}
		
	}
}
